// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';

// 申明请求对象
const qcDefectRequest = {
    // dict请求的基本url
    BASE_URL : confing.QC_URL + "/defect",

    /**
     * 删除缺陷
     * @param {*} defectId 
     * @param {*} callback 
     */
    delete(defectId,callback){
        let url = this.BASE_URL + "/delete?defectId=" + defectId;
        request.delete(url,callback);
    },
    edit(defect,callback){
        console.log(defect);
        let url = this.BASE_URL + "/update";
        if(defect != undefined && defect.defectId != undefined){
            request.put(url,defect,callback)
        }
    },
    selectById(defectId,callback){
        if(defectId){
            // 准备url
            let url = this.BASE_URL + "/selectById?defectId=" + defectId;
            request.get(url,callback);
        }
        // 如果没有defectId，不做任何处理
    },
    /**
     * 保存缺陷信息
     * @param {*} defect 
     * @param {*} callback 
     */
    save(defect,callback){
        if(defect){
            request.post(this.BASE_URL + "/save",defect,callback);
        }
    },

    /**
     * 遍历数据
    */
    // 请求的API
    list(page = 1,limit = 10,defect,callbcak){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(defect){
            if(defect.defectName){
                url += "&defectName=" + defect.defectName;
            }
            if(defect.indexType){
                url += "&indexType=" + defect.indexType;
            }
            if(defect.defectLevel){
                url += "&defectLevel=" + defect.defectLevel;
            }
        }
        // 发送请求
        request.get(url,callbcak);
    }
}

// 将dictRequest暴漏出去
export default qcDefectRequest;